package com.wpw.dream.masteworker;

import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;

public class Worker extends Thread {


	private ConcurrentLinkedQueue<Task> taskQueue;
	
	private ConcurrentHashMap<Object, Object> resMap;


	public void setTaskQueue(ConcurrentLinkedQueue<Task> taskQueue) {
		this.taskQueue = taskQueue;
	}

	public void setResMap(ConcurrentHashMap<Object, Object> resMap) {
		this.resMap = resMap;
	}

	@Override
	public void run() {
		while (true) {
			String uid = UUID.randomUUID().toString();
			Task task = taskQueue.poll();
			if (task == null) break;
			Object res = task.handle();
			resMap.put(uid, res);
		}
		
	}
	
}
